#import "OmJoinMemberVC.h"
#import "OmBuyKingHatVC.h"
#import "UserApiGetUserPageInfoModel.h"
@interface OmJoinMemberVC ()
@property (nonatomic, strong) UIImageView *backgroundImageView;
@property (nonatomic, strong) UILabel *labelMyLevel;
@property (nonatomic, strong) UILabel *labelPayType;
@property (nonatomic, strong) UILabel *labelBlueDiamond;
@property (nonatomic, strong) UILabel *labelKingHat;
@property (nonatomic, strong) UILabel *labelBuy0;
@property (nonatomic, strong) UILabel *labelBuy1;
@property (nonatomic, strong) UIButton *buttonDiamondBuy;
@property (nonatomic, strong) UIButton *buttonHatBuy;
@property (nonatomic, strong) UIImageView *memberIcon;
@property (nonatomic, strong) UILabel *daysLabel;
@property (nonatomic, strong) UILabel *noMemberLabel;
@end
@implementation OmJoinMemberVC
#pragma mark - Event
- (void)refreshSelf {
    self.noMemberLabel.hidden = YES;
    self.memberIcon.hidden = YES;
    self.daysLabel.hidden = YES;
    NSString *url = [[CYURLUtils sharedCYURLUtils] makeURLWithC:@"user_api" A:@"get_user_page_info"];
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    param[@"to_user_id"] = curUser.id;
    [CYNET POST:url parameters:param responseCache:^(id responseObject) {
    } success:^(id responseObject) {
        UserApiGetUserPageInfoModel *model = [UserApiGetUserPageInfoModel mj_objectWithKeyValues:responseObject];
        if (!(model.blue || model.crown)) {
            self.noMemberLabel.hidden = NO;
        } else if (model.crown) {
            [self.memberIcon setImage:IMAGE_NAMED(@"OmKingHat")];
            self.memberIcon.hidden = NO;
            self.daysLabel.hidden = NO;
            self.daysLabel.fp_text([NSString stringWithFormat:@"%zd%@", model.crown_day, ASLocalizedString(@"天")]);
        } else if (model.blue) {
            [self.memberIcon setImage:IMAGE_NAMED(@"OmBlueDiamond")];
            self.memberIcon.hidden = NO;
            self.daysLabel.hidden = NO;
            self.daysLabel.fp_text([NSString stringWithFormat:@"%zd%@", model.blue_day, ASLocalizedString(@"天")]);
        }
    } failure:^(NSString *error) {
    } hasCache:NO];
}
- (void)eventButtonDiamondBuyTap {
    NSLog(@"diamond");
    OmBuyKingHatVC *vc = [[OmBuyKingHatVC alloc] initWithType:MemberTypeBlueDiamond];
    [self.navigationController pushViewController:vc animated:YES];
}
- (void)eventButtonHatBuyTap {
    NSLog(@"hat");
    OmBuyKingHatVC *vc = [[OmBuyKingHatVC alloc] initWithType:MemberTypeKingHat];
    [self.navigationController pushViewController:vc animated:YES];
}
#pragma mark - ConstructionScript
- (void)configSelf {
    [self setHiddenForTabBar:YES navigationBar:NO];
    self.title = ASLocalizedString(@"开通会员");
    [self changeScrollMode:ScrollModePortrait];
}
- (void)allocateComponents {
    self.backgroundImageView = [[UIImageView alloc] initWithImage:IMAGE_NAMED(@"OmJoinMember")];
    [self.scrollContentView addSubview:self.backgroundImageView];
    self.labelMyLevel = [[UILabel alloc] init].fp_text(ASLocalizedString(@"我的等级:")).fp_font(MediumRPXFont(14)).fp_textColor(HexadecimalColor(@"#333333"));
    [self.scrollContentView addSubview:self.labelMyLevel];
    
    self.labelBlueDiamond = [[UILabel alloc] init].fp_text(ASLocalizedString(@"蓝钻")).fp_font(MediumRPXFont(14)).fp_textColor(HexadecimalColor(@"#333333"));
    [self.scrollContentView addSubview:self.labelBlueDiamond];
    self.labelKingHat = [[UILabel alloc] init].fp_text(ASLocalizedString(@"皇冠")).fp_font(MediumRPXFont(14)).fp_textColor(HexadecimalColor(@"#333333"));
    [self.scrollContentView addSubview:self.labelKingHat];
    self.labelBuy0 = [[UILabel alloc] init].fp_text(ASLocalizedString(@"开通")).fp_font(MediumRPXFont(12)).fp_textColor(HexadecimalColor(@"#FFFFFF"));
    [self.scrollContentView addSubview:self.labelBuy0];
    self.labelBuy1 = [[UILabel alloc] init].fp_text(ASLocalizedString(@"开通")).fp_font(MediumRPXFont(12)).fp_textColor(HexadecimalColor(@"#FFFFFF"));
    [self.scrollContentView addSubview:self.labelBuy1];
    self.buttonDiamondBuy = [[UIButton alloc] init].fp_addTargetActionForControlEvents(self, @selector(eventButtonDiamondBuyTap), UIControlEventTouchUpInside);
    [self.scrollContentView addSubview:self.buttonDiamondBuy];
    self.buttonHatBuy = [[UIButton alloc] init].fp_addTargetActionForControlEvents(self, @selector(eventButtonHatBuyTap), UIControlEventTouchUpInside);
    [self.scrollContentView addSubview:self.buttonHatBuy];
    self.memberIcon = [[UIImageView alloc] init];
    [self.scrollContentView addSubview:self.memberIcon];
    self.daysLabel = [[UILabel alloc] init].fp_font([UIFont systemFontOfSize:14 weight:UIFontWeightMedium]).fp_textColor(HexadecimalColor(@"#999999"));
    [self.scrollContentView addSubview:self.daysLabel];
    self.noMemberLabel = [[UILabel alloc] init].fp_text(ASLocalizedString(@"无")).fp_textColor(HexadecimalColor(@"#333333")).fp_font(MediumRPXFont(14));
    [self.scrollContentView addSubview:self.noMemberLabel];
    
    UIView *view = [[UIView alloc] init].fp_backgroundColor([UIColor whiteColor]);
    [self.scrollContentView addSubview:view];
    [view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.buttonDiamondBuy);
        make.left.right.equalTo(self.scrollContentView);
        make.height.equalTo(@(RPX(56)));
    }];
    
    self.labelPayType = [[UILabel alloc] init].fp_text(ASLocalizedString(@"充值类型")).fp_font(MediumRPXFont(55)).fp_textColor(HexadecimalColor(@"#999999"));
    [self.scrollContentView addSubview:self.labelPayType];
}
- (void)layoutComponents {
    [self.backgroundImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(self.scrollContentView);
        make.height.equalTo(self.backgroundImageView.mas_width).multipliedBy(459.0/750);
        make.bottom.equalTo(self.scrollContentView).offset(RPX(-800));
    }];
    [self.labelMyLevel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.scrollContentView).offset(RPX(21));
        make.left.equalTo(self.scrollContentView).offset(RPX(20));
    }];
    [self.labelPayType mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.scrollContentView).offset(RPX(85));
        make.left.equalTo(self.scrollContentView).offset(RPX(20));
    }];
    [self.labelBlueDiamond mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.scrollContentView).offset(RPX(140));
        make.left.equalTo(self.scrollContentView).offset(RPX(54));
    }];
    [self.labelKingHat mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.scrollContentView).offset(RPX(195));
        make.left.equalTo(self.scrollContentView).offset(RPX(54));
    }];
    [self.labelBuy0 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.scrollContentView).offset(RPX(141));
        make.left.equalTo(self.scrollContentView).offset(RPX(315));
    }];
    [self.labelBuy1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.scrollContentView).offset(RPX(196));
        make.left.equalTo(self.scrollContentView).offset(RPX(315));
    }];
    [self.buttonDiamondBuy mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@(RPX(65)));
        make.height.equalTo(@(RPX(30)));
        make.left.equalTo(self.scrollContentView).offset(RPX(295));
        make.top.equalTo(self.scrollContentView).offset(RPX(132));
    }];
    [self.buttonHatBuy mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@(RPX(65)));
        make.height.equalTo(@(RPX(30)));
        make.left.equalTo(self.scrollContentView).offset(RPX(295));
        make.top.equalTo(self.scrollContentView).offset(RPX(187));
    }];
    [self.memberIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.labelMyLevel);
        make.left.equalTo(self.labelMyLevel.mas_right).offset(RPX(10));
        make.width.height.equalTo(@(RPX(20)));
    }];
    [self.noMemberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.labelMyLevel);
        make.left.equalTo(self.labelMyLevel.mas_right).offset(RPX(10));
    }];
    [self.daysLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.memberIcon);
        make.left.equalTo(self.memberIcon.mas_right).offset(10);
    }];
}
@end
